package com.duke.javaagent.bytebuddy02;

import com.duke.javaagent.bytebuddy02.interceptor.StringUtilInterceptor;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.utility.JavaModule;

import java.security.ProtectionDomain;

/**
 * @author gjy
 * @create 2024-12-10 12:44 PM
 */
public class AgentTransformer implements AgentBuilder.Transformer {
    @Override
    public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
                                            TypeDescription typeDescription,
                                            ClassLoader classLoader,
                                            JavaModule javaModule,
                                            ProtectionDomain protectionDomain) {

        System.out.println("打印类的名字： "+ typeDescription.getActualName());
        return builder
                .method(ElementMatchers.isStatic())
                .intercept(MethodDelegation.to(new StringUtilInterceptor()));
    }
}
